from base.layer import Layer
import numpy as np
class Activation(Layer):
    def __init__(self,activation,activation_prime):
        super().__init__()
        self.activation = activation
        self.activation_prime = activation_prime

    def forward(self,x):
        self.x = x
        return self.activation(self.x)

    def backward(self,y_grad,learning_rate):
        return np.multiply(y_grad,self.activation_prime(self.x))

class Tanh(Activation):
    def __init__(self):
        tanh = lambda x: np.tanh(x)
        tanh_prime = lambda x: 1 - np.tanh(x)**2
        super().__init__(tanh, tanh_prime)